<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of cInstall
 *
 * @author prezes
 */
class cInstall extends cController{
    
    public function __construct($model) {
        parent::__construct($model);
        $this->model->connectionForm();
    }
    
    public function connect(){
        $this->model->connectionFormValidate();        
        
    }
    
    public function importdb(){
        
        
        $sqlDump = file_get_contents( './config/database.sql');
        $sqlDump = explode ( ';' , $sqlDump );
        
        array_pop( $sqlDump ); // removes empty symbol after last ';' in file
        foreach( $sqlDump as $query)  $this->model->error[] = DbConnection::getInstance()->adminQuery( $query );
        
        if( isset($this->model->error)) $this->model->error = array_filter($this->model->error);
        
        if( empty($this->model->error)) { $this->model->configForm(); }
        
        
    }
    
    public function upload(){
        if( isset($_FILES['favicon'])){
            if($_FILES['favicon']['error']){
                $this->model->error[] = "Error loading Favicon";
            }else            move_uploaded_file ($_FILES['favicon'], './tamplates/favicon.ico');
        
        }
        
        if( isset($_FILES['logo'])){
            if($_FILES['favicon']['error']){
                $this->model->error[] = "Error loading Logo";
            }else            move_uploaded_file ($_FILES['favicon'], './tamplates/logo.jpg');
        
        }
        //TODO: ADD ROOT
        //TODO: WRITE  Website title
        
        if(empty($this->model->error) ){ $this->model->instaled(); }
        else $this->model->configForm();
    }
}
